package Java常用类的学习;
//向TreeSet容器中加入4个雇员信息，并按照工资高低进行排序

import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class Employee implements Comparable {
    private String name;
    private int salary;
    public Employee(String name, int salary){
        this.name=name;
        this.salary=salary;

    }
    public String toString(){
        return "name:"+name+","+"salary:"+salary;
    }


    public boolean equals(Object o){
        if(!(o instanceof Employee)) return false;
        Employee employee=(Employee) o;
//        if(this.name.equals(employee.name)&&this.salary==employee.salary) return true;
        if(this.name==employee.name&&this.salary==employee.salary) return true;
        else return false;
    }
    public int hashCode(){
        int result;
        result=(name==null?0:hashCode());
        return result;
    }
    @Override
    public int  compareTo(Object o) {
                Employee e=(Employee) o;
                int result=salary>e.salary?1:(salary==e.salary?0:-1);
                if(result==0) return name.compareTo(e.name);
                return result;
    }

    public static void main(String[] args) {
        String s1="wangxin";
        String s2="wangxin";
        System.out.println(s1==s2);
        System.out.println(s1.equals(s2));
        Set<Employee> set =new TreeSet<Employee>();
        set.add(new Employee("wangxin",6000));
        set.add(new Employee("lihui",4000));
        set.add(new Employee("xx",3000));
        Iterator<Employee> it=set.iterator();
        for(;it.hasNext();){
            Employee ss=it.next();
            System.out.println(ss);

        }
    }
}
